package com.example.orchid.paper.util;

import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * PhoneUtils 手机简易工具类
 * Created by Orchid on 2015-10-12.
 */
public class PhoneUtils {
    /**
     * 获取应用名
     * @param activity 上下文
     * @return
     */
    public static String getApplicationName(Activity activity) {
        PackageManager packageManager = null;
        ApplicationInfo applicationInfo = null;
        packageManager = activity.getPackageManager();
        try {
            applicationInfo = packageManager.getApplicationInfo(activity.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        String applicationName = (String) packageManager.getApplicationLabel(applicationInfo);
        return applicationName;
    }

    /**
     * 获取版本号
     * @param activity 上下文
     * @return
     */
    public static PackageInfo getPackageInfo(Activity activity) {
        PackageInfo packageInfo = null;
        PackageManager pm = activity.getPackageManager();
        try {
            packageInfo = pm.getPackageInfo(activity.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return packageInfo;
    }
}
